#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> findmin(int n)
{
    vector<int> min_factor(n + 1);
    for (int i = 1; i <= n; i++)
    {
        min_factor[i] = i;
    }

    for (int i = 2; i <= n; i++)
    {
        if (min_factor[i] == i)
        {
            for (int j = i * i; j <= n; j += i)
            {
                if (min_factor[j] == j)
                {
                    min_factor[j] = i;
                }
            }
        }
    }
    return min_factor;
}
int main()
{
    int n;
    cin >> n;
    
    vector<int> sore(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> sore[i];
    }

    vector<int> min_factor;
    min_factor = findmin(n);

    vector<int> dp(n + 1, -1e9);
    dp[1] = sore[1];

    for (int i = 1; i <= n; i++)
    {
        for (int j = i + min_factor[i]; j <= n; j += min_factor[i])
        {
            dp[j] = max(dp[j], dp[i] + sore[j]);
        }
    }

    cout << dp[n] << endl;
    return 0;
}